package com.ffapp.helper.util;

import android.app.Activity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.ffapp.helper.R;
import com.ffapp.helper.basis.BasisActivity;
import com.flyco.dialog.widget.NormalDialog;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class OwnerConfirmDialog extends NormalDialog {

    @BindView(R.id.edit_name)
    EditText edit_name;
    @BindView(R.id.text_title)
    TextView text_title;
    BasisActivity mActivity;
    String title;

    OnNamePostListener mListener;

    public OwnerConfirmDialog(BasisActivity context,OnNamePostListener listener) {
        super(context);
//            setCanceledOnTouchOutside(false);
        mActivity = context;
        this.mListener = listener;
    }
    public OwnerConfirmDialog(BasisActivity context,OnNamePostListener listener,String title) {
        super(context);
//            setCanceledOnTouchOutside(false);
        mActivity = context;
        this.mListener = listener;
        this.title = title;
    }

    @Override
    public View onCreateView() {
//        return super.onCreateView();
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.patrol_owner_sign_dialog, null);
        ButterKnife.bind(this, inflate);

//        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(SystemParamsUtils.getScreenWidth(), LinearLayout.LayoutParams.MATCH_PARENT);
//        recyclerview.setLayoutParams(params);


        return inflate;
    }

    //    @Override
    public View onCreatePopupView() {
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.patrol_owner_sign_dialog, null);
        ButterKnife.bind(this, inflate);

        return inflate;
    }

    @Override
    public void setUiBeforShow() {
            initData();
    }

    private void initData() {
        if(!TextUtils.isEmpty(title)){
            text_title.setText(title);
        }
    }


    @OnClick(R.id.btn_cancel)
    void close(){
        dismiss();
    }

    @OnClick(R.id.btn_ok)
    void post(){
        String name = edit_name.getText().toString().trim();
        if(TextUtils.isEmpty(name)){
            mActivity.showToast("请输入名称");
            return;
        }
        if(mListener != null){
            mListener.onNamePost(name);
        }
        dismiss();
    }

    public interface OnNamePostListener{
        abstract void onNamePost(String name);
    }

}